

import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';

import 'CircleDetailPage.dart';
import 'model/CircleHomeResp.dart';

class RecommendationCircleItem extends StatelessWidget {

  final List<RecommendationHomeCircleInfo>? infos;
  final String title;
  final String bgUrl;
  final Function()? more;

  const RecommendationCircleItem(this.infos, this.title, this.bgUrl, this.more, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(height: 222,
      decoration: BoxDecoration(
          image: DecorationImage(
            image: LoadImage.getImageProvider(bgUrl),
            fit: BoxFit.cover,
          ),
          borderRadius: BorderRadius.all(Radius.circular(13))
      ),
      child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        InkWell(onTap: () => {if (more != null) more!()},
            child: Padding(padding: EdgeInsets.only(left: 11, top: 11, bottom: 11), child: Row(children: [
              Text(title, style: TS(15, Colors.white)),
              Spacer(),
              SmartButton(width: 34, height: 20, radius: 17, cornerPosition: 9, backgroundColor: Color.fromRGBO(0, 0, 0, 0.1), borderColor: Colors.transparent,
                drawableLeft: LoadImage('ic_white_right_arrow'),)
            ]))
        ),
        DD(paddingLeft: 11, paddingRight: 17, color: Color.fromRGBO(0xff, 0xff, 0xff, 0.7), dashWidth: 2,),
        if ((infos?.length ?? 0) >= 1) 
          ...addItems(context, '1', infos![0]),
        if ((infos?.length ?? 0) >= 2)
          ...addItems(context, '2', infos![1]),
        if ((infos?.length ?? 0) >= 3)
          ...addItems(context, '3', infos![2]),
      ]),
    );
  }
  
  List<Widget> addItems(BuildContext context, String num, RecommendationHomeCircleInfo info) {
    List<Widget> result = [];
    result.add(H(13));
    result.add(
        GestureDetector(onTap: () => circleDetail(context, info.id),
            child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
              W(12),
              Text(num, style: TS(17, C.yellow)),
              W(8),
              Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
                Text(info.title ?? '', style: TS(15, Colors.white)),
                H(1),
                Text('有${info.num}位好友关注了该圈子', style: TS(11, Color.fromRGBO(0xff, 0xff, 0xff, 0.7)))
              ],)
            ])
        )
    );
    return result;
  }

  circleDetail(BuildContext context, int? circleId) {
    AppNavigator.push(context, RouteName.CIRCLE_DETAIL, arguments: {'circleDetailType': CircleDetailType.inner, 'circleId': circleId});
  }
}